{extend name="main" /}
{block name="css"}
<style>
    #nav_callbar {
        background-color: #fff; padding: 0; border-radius: 4px;
    }
    #nickname,#nickname_1,#nickname_2{ display: inline-block;}
    #exten_status{margin-left: 10px;}
    #nav_callbar>.btn.disabled, #nav_callbar>.btn[disabled] {
        opacity: .45;
    }
    .layui-layer-title{
        background: #337ab7 !important;
        color: #ffffff !important;
    }
</style>
{/block}

{block name="script"}
<script type="text/javascript">

    $(function () {
        //ajax获取菜单配置
        $.ajax({ //获取菜单
            url:'{:url("Index/ajaxMenu")}',
            type:'post',
            dataType:'json',
            data:{},
            success:function (response) {
                if(response.code === 0){
                    $('.sidebar-menu').addMenus(response.data);
                    $('.sidebar-menu a[target="iframe-1"]')[0].click();//默认显示的tab
                }else{
                    toastr.error(response.msg);
                }
            }
        });


        /**
         * 执行编辑用户配置文件
         */
        $('#user_setting').on('click', function () {
            var area = [$(window).width() > 800 ? '800px' : '95%', $(window).height() > 520 ? '520px' : '95%'];
            layer.open({
                type: 2,
                title: '用户信息设置',
                maxmin: true,
                scrollbar:false,
                anim:0,
                shade:0,//隐藏遮罩层
                area : area,
                content: '{:url("AdminUser/editProfile")}',
                btn:['保存','取消'],
                btnAlign:'c',
                yes:function (index,layero) {
                    var iframe = layero.find("iframe")[0].contentWindow.document;
                    $(iframe).find('.submit_btn').click();
                },
                btn2:function (index,layero) {
                    layer.close(index);
                }
            });
        });

        $('#user_setting__OLD').on('click', function () {
            var url = '{:url("AdminUser/edit")}';
            var mid = '50';

            if( $('iframe[name="iframe-'+ mid +'"]').length===0 ) {
                    var id = "iframe-"+ mid;
                    var iframe_html = '<iframe id="' + id + '" class="default-iframe active-iframe" ' +
                        'name="' + id + '" scrolling="auto" frameborder="0" width="100%" height="100%" src="' + url + '"></iframe>';
                    var $newIframe = $(iframe_html);
                    $('#tab-content').append($newIframe);

                    //2）增加tab标签
                    $('.active_tab').removeClass('active_tab');
                    var tabs = '<span class="tab-item-btn active_tab" data-id="' + id + '">' + '用户设置'
                        + '&nbsp;<i class="fa fa-close tab-item-close"></i></span>';
                    var $tab = $(tabs);
                    $('#tab-menu').append($tab);
                    $tab.click();

                    var tab_position_left = $('.tab-item-btn[data-id="' + id + '"]').position().left;
                    var tab_width = $('.tab-item-btn[data-id="' + id + '"]').outerWidth(true);
                    var tabs_width = tab_position_left + tab_width - $('.tabLeft').outerWidth(true);
                    //获取滚动条的left长度
                    var tab_menu_scrollLeft = $('#tab-menu').scrollLeft();
                    //判断选项卡是否溢出了
                    if (tabs_width - $('#tab-menu').width() > 0) {
                        $('#tab-menu').stop().animate({scrollLeft: tab_menu_scrollLeft + parseFloat(tab_width.toFixed(1))}, 500);
                    }

            }else{
                //激活当前iframe
                $('#tab-menu > .tab-item-btn[data-id="iframe-'+ mid +'"]')[0].click();
            }

        })

    });

    var ccIP = '{$Think.config.cc.cc_api_url}';
    var exten = '{$Think.Session.admin.extennum}';
    var nextpop_mix_msec = 5 * 1000;
    var lastPopScreenTime = Date.now();
    $(function(){
        agentstate('{$initState->dndState}');
        agentstate('{$initState->hintState}');

        serverpush(exten);

    });

</script>
{/block}
